# Contributor: Joseph Benden <joe@benden.us>
# Maintainer: Joseph Benden <joe@benden.us>
pkgname=stgit
pkgver=2.4.7
pkgrel=1
pkgdesc="Manage a stack of patches using GIT as a backend"
arch="aarch64 ppc64le x86_64 loongarch64"
url="http://www.github.com/stacked-git/stgit"
license="GPL-2.0-or-later"
options="!check" # unit-tests fail due to iconv usage
depends="openssl"
makedepends="cargo asciidoc xmlto perl openssl-dev"
subpackages="
	$pkgname-doc
	$pkgname-zsh-completion
	$pkgname-fish-completion
	$pkgname-bash-completion
	$pkgname-vim:_vim:noarch
	$pkgname-emacs:_emacs:noarch
	"
source="https://github.com/stacked-git/stgit/releases/download/v$pkgver/stgit-$pkgver.tar.gz"

prepare() {
	default_prepare

	cargo fetch --target="$CTARGET" --locked
}

check() {
	make \
		prefix=/usr \
		mandir=/usr/share/man/ \
			test
}

build() {
	make \
		prefix=/usr \
		mandir=/usr/share/man/ \
			all doc
}

package() {
	make \
		DESTDIR="$pkgdir" \
		prefix=/usr \
		mandir=/usr/share/man/ \
			install-all

	# shell completion
	rm -rf "$pkgdir"/usr/share/stgit/completions
	install -Dm0644 completion/stgit.bash \
		"$pkgdir"/usr/share/bash-completion/completions/stgit
	install -Dm0644 completion/stgit.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_stgit
	install -Dm0644 completion/stg.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/stg.fish

	# lisp
	install -Dm0644 contrib/stgit.el -t "$pkgdir"/usr/share/emacs/site-lisp

	# vim
	install -Dm0644 contrib/vim/ftdetect/stg.vim -t \
		"$pkgdir"/usr/share/vim/vimfiles/ftdetect
	for vimsyntax in contrib/vim/syntax/*.vim; do
		install -Dm0644 "$vimsyntax" -t "$pkgdir"/usr/share/vim/vimfiles/syntax
	done
}

_emacs() {
	pkgdesc="stg plugin for emacs"
	install_if="$pkgname=$pkgver-r$pkgrel emacs"
	amove usr/share/emacs
}

_vim() {
	pkgdesc="vim filetype and syntax for stgit files"
	install_if="$pkgname=$pkgver-r$pkgrel vim"
	amove usr/share/vim/vimfiles
}

sha512sums="
855f6bd3319c2be3192fb08168e335ef4210e200197554aaa1f5b99c599a9995ef1b94d377630b65ce52f1dcbd9d72c41d8d5f00e41b4f005ae14ca8557c58f0  stgit-2.4.7.tar.gz
"
